package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ItemKnowledgeDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.ItemKnowledge;
import com.itheima.service.ItemKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service(interfaceClass = ItemKnowledgeService.class)
@Transactional
public class ItemKnowledgeServiceImpl implements ItemKnowledgeService {
    @Autowired
    private ItemKnowledgeDao itemKnowledgeDao;

    public void add(List<ItemKnowledge> list) {
        if(list != null && list.size()>0){
            for (ItemKnowledge itemKnowledge : list) {
                itemKnowledgeDao.add(itemKnowledge);
            }
        }
    }

    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<ItemKnowledge> page = itemKnowledgeDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    public ItemKnowledge findById(Integer id) {
        return itemKnowledgeDao.findById(id);
    }

    public void edit(ItemKnowledge itemKnowledge) {
        itemKnowledgeDao.edit(itemKnowledge);
    }

    public void delete(Integer id) {
        itemKnowledgeDao.delete(id);
    }
}
